home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / lightning.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  24.7 KB  |  835 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. includeEffectsGlobals();
  18.  
  19. //
  20. // lightning
  21. // -    makeLightning
  22. // -        makeLightning
  23. // -    createShader
  24. // -    createShader
  25.  
  26. proc createLightningSelectHandleExpr( string $group )
  27. //
  28. // Description:
  29. //
  30. //     The selection handle for the lightning group gets diplayed at
  31. // the center of the lightning bolt.  This expression finds that location
  32. // and sets the selection handle's position to it.
  33. //
  34. {
  35.     // Get the object from which the lightning is coming.
  36.     //
  37.     string $fromObjs[] = getLightningFromPoint( $group );
  38.     string $fromObj = $fromObjs[0];
  39.  
  40.     string $fromDirs[] = getLightningFromDirection( $group );
  41.     string $fromDirection = $fromDirs[0];
  42.  
  43.     // Get the object from which the lightning is ending.
  44.     //
  45.     string $toObjs[] = getLightningToPoint( $group );
  46.     string $toObj = $toObjs[0];
  47.  
  48.     string $toDirs[] = getLightningToDirection( $group );
  49.     string $toDirection = $toDirs[0];
  50.  
  51.     // To display select-handle at the center, create a expression.
  52.     //
  53.     string $selectHandleX = ($group+".selectHandleX");
  54.     string $selectHandleY = ($group+".selectHandleY");
  55.     string $selectHandleZ = ($group+".selectHandleZ");
  56.  
  57.     string $expr = "";
  58.     $expr += ("float $fromX = "+$fromObj+".translateX;\n");
  59.     $expr += ("float $fromY = "+$fromObj+".translateY;\n");
  60.     $expr += ("float $fromZ = "+$fromObj+".translateZ;\n");
  61.  
  62.     $expr += ("float $toX = "+$toObj+".translateX;\n");
  63.     $expr += ("float $toY = "+$toObj+".translateY;\n");
  64.     $expr += ("float $toZ = "+$toObj+".translateZ;\n");
  65.  
  66.     $expr += ("float $fromDirX = "+$fromDirection+".translateX;\n");
  67.     $expr += ("float $fromDirY = "+$fromDirection+".translateY;\n");
  68.     $expr += ("float $fromDirZ = "+$fromDirection+".translateZ;\n");
  69.  
  70.     $expr += ("float $toDirX = "+$toDirection+".translateX;\n");
  71.     $expr += ("float $toDirY = "+$toDirection+".translateY;\n");
  72.     $expr += ("float $toDirZ = "+$toDirection+".translateZ;\n");
  73.  
  74.     $expr += ("vector $from = << $fromX, $fromY, $fromZ>>;\n");
  75.     $expr += ("vector $to = << $toX, $toY, $toZ>>;\n");
  76.     $expr += ("vector $fromDirP = << $fromDirX, $fromDirY, $fromDirZ>>;\n");
  77.     $expr += ("vector $toDirP = << $toDirX, $toDirY, $toDirZ>>;\n");
  78.  
  79.     $expr += ("vector $fromDir = ($fromDirP - $from) * 5.0;\n");
  80.     $expr += ("vector $toDir = ($to - $toDirP) * 5.0;\n");
  81.  
  82.     $expr += ("float $start = "+$group+".lightningStart;\n");
  83.     $expr += ("float $end = "+$group+".lightningEnd;\n");
  84.     $expr += ("float $ratio = $start + ($end - $start) * 0.5;\n");
  85.  
  86.     $expr += ("vector $handleP=hermite($from,$to,$fromDir,$toDir,$ratio);\n");
  87.  
  88.     $expr += ($selectHandleX+" = $handleP.x;\n");
  89.     $expr += ($selectHandleY+" = $handleP.y;\n");
  90.     $expr += ($selectHandleZ+" = $handleP.z;\n");
  91.  
  92.     expression -alwaysEvaluate false -string $expr;
  93. }
  94.  
  95. proc string makeLightningGroup
  96.     (
  97.         string $name,
  98.         string $fromObj,
  99.         string $toObj,
  100.         int $segmentCount,
  101.         float $thickness,
  102.         float $maxSpread,
  103.         float $start,
  104.         float $end,
  105.         float $glowIntensity
  106.     )
  107. {
  108.     // Create a group node.
  109.     //
  110.     group -empty;
  111.     if( $name == "" )
  112.     {
  113.         rename "Lightning#";
  114.     }
  115.     else
  116.     {
  117.         rename $name;
  118.     }
  119.  
  120.     string $group = getSelectedObject( 0 );
  121.  
  122.     // Do not allow to do transformation on the lightning group.
  123.     //
  124.     lockTransformations( $group );
  125.  
  126.  
  127.     // This attribute is for checking if the node is a lightning node.
  128.     //
  129.     addAttr -at message -ln "_lightningGroupObject" $group;
  130.  
  131.     // Add attributes for management.
  132.     //
  133.     addMarkingAttribute( $group, "lightningFromObject", 0 );
  134.     addMarkingAttribute( $group, "lightningFromPosition", 0 );
  135.     addMarkingAttribute( $group, "lightningFromDirection", 0 );
  136.     addMarkingAttribute( $group, "lightningToObject", 0 );
  137.     addMarkingAttribute( $group, "lightningToPosition", 0 );
  138.     addMarkingAttribute( $group, "lightningToDirection", 0 );
  139.     addMarkingAttribute( $group, "lightningParticleObject", 0 );
  140.     addMarkingAttribute( $group, "lightningSurface", 0 );
  141.     addMarkingAttribute( $group, "lightningShader", 0 );
  142.     //addMarkingAttribute( $group, "lightningPointLights", 1 );
  143.  
  144.     // Connect from and end object with the group.
  145.     //
  146.     markObjectWithAttribute( $fromObj, $group, "lightningFromObject" );
  147.     markObjectWithAttribute( $toObj, $group, "lightningToObject" );
  148.  
  149.  
  150.     // Add attributes for lightning controls.
  151.     //
  152.     addControlAttribute( $group, "thickness", $thickness, 0, 10 );
  153.     addControlAttribute( $group, "maxSpread", $maxSpread, 0, 10 );
  154.     addControlAttribute( $group, "lightningStart", $start, 0, 1 );
  155.     addControlAttribute( $group, "lightningEnd", $end, 0, 1 );
  156.     addControlAttribute( $group, "glowIntensity", $glowIntensity, 0, 100 );
  157.     addControlAttribute( $group, "lightIntensity", 2.0, 0, 100 );
  158.     addControlAttribute( $group, "colorR", 0.5, 0, 1 );
  159.     addControlAttribute( $group, "colorG", 1, 0, 1 );
  160.     addControlAttribute( $group, "colorB", 1, 0, 1 );
  161.  
  162.  
  163.     string $sl[];
  164.     string $constrainNode[];
  165.  
  166.     //float $fromPos[] = `getAttr ($fromObj+".translate")`;
  167.     //float $toPos[] = `getAttr ($toObj+".translate")`;
  168.     float $fromPos[] = `xform -q -ws -t $fromObj`;
  169.     float $toPos[] = `xform -q -ws -t $toObj`;
  170.     vector $fromV = << $fromPos[0], $fromPos[1], $fromPos[2] >>;
  171.     vector $toV = << $toPos[0], $toPos[1], $toPos[2] >>;
  172.     vector $diffV = $toV - $fromV;
  173.     float $dist = mag($diffV);
  174.  
  175.     // For the start of the lightning.
  176.     //
  177.     createPrimitive nullObject;
  178.     rename "fromPoint#";
  179.     $sl = `ls -sl`;
  180.     string $fromPoint = $sl[0];
  181.     string $fromPointShape = getShapeFromObject( $fromPoint, 0, 0 );
  182.     setAttr ($fromPointShape+".visibility") 0;
  183.     //setAttr ($fromPoint+".template") 1;
  184.     setAttr ($fromPoint+".inheritsTransform") 0;
  185.  
  186.     select $fromObj $fromPoint;
  187.     $constrainNode = `pointConstraint -weight 1`;
  188.     setAttr ($constrainNode[0]+".visibility") 0;
  189.     select $fromObj $fromPoint;
  190.     $constrainNode = `orientConstraint -weight 1`;
  191.     setAttr ($constrainNode[0]+".visibility") 0;
  192.     markObjectWithAttribute($fromPoint, $group, "lightningFromPosition");
  193.  
  194.     select -cl;
  195.     string $fromJoint1 = `joint -p 0 0 0`;
  196.     string $fromJoint2 = `joint -p 3 0 0`;
  197.     joint -e -zso -oj xyz $fromJoint2;
  198.     setAttr ($fromJoint2+".visibility") 0;
  199.     setAttr ($fromJoint1+".template") 1;
  200.  
  201.     select $fromPoint $fromJoint1;
  202.     $constrainNode = `pointConstraint -weight 1`;
  203.     setAttr ($constrainNode[0]+".visibility") 0;
  204.  
  205.     // Create a locator as "fromDirectionHandle".
  206.     //
  207.     vector $fromHandleP = $fromV + $diffV * 0.2;
  208.  
  209.     createPrimitive nullObject;
  210.     move ($fromHandleP.x) ($fromHandleP.y) ($fromHandleP.z);
  211.     rename "fromDirHandle#";
  212.     $sl = `ls -sl`;
  213.     string $fromDirHandle = $sl[0];
  214.     parent $fromDirHandle $fromPoint;
  215.  
  216.     select $fromDirHandle $fromJoint2;
  217.     $constrainNode = `pointConstraint -weight 1`;
  218.     setAttr ($constrainNode[0]+".visibility") 0;
  219.  
  220.     // Create a locator as "fromDirection".
  221.     // "fromDirection" point-constrained to "fromDirectionHandle".
  222.     //
  223.     createPrimitive nullObject;
  224.     move ($fromHandleP.x) ($fromHandleP.y) ($fromHandleP.z);
  225.     rename "fromDir#";
  226.     $sl = `ls -sl`;
  227.     string $fromDirection = $sl[0];
  228.     setAttr ($fromDirection+".visibility") 0;
  229.     setAttr ($fromDirection+".inheritsTransform") 0;
  230.     parent $fromDirection $fromPoint;
  231.  
  232.     select $fromDirHandle $fromDirection;
  233.     $constrainNode = `pointConstraint -weight 1`;
  234.     setAttr ($constrainNode[0]+".visibility") 0;
  235.     markObjectWithAttribute($fromDirection, $group, "lightningFromDirection");
  236.  
  237.     // Group the "from" controls.
  238.     //
  239.     select $fromJoint1 $fromPoint;
  240.     group;
  241.     rename("fromControl#");
  242.     string $fromControl = getSelectedObject( 0 );
  243.  
  244.     // For the end of the lightning.
  245.     //
  246.     createPrimitive nullObject;
  247.     rename "toPoint#";
  248.     $sl = `ls -sl`;
  249.     string $toPoint = $sl[0];
  250.     string $toPointShape = getShapeFromObject( $toPoint, 0, 0 );
  251.     setAttr ($toPointShape+".visibility") 0;
  252.     //setAttr ($toPoint+".template") 1;
  253.     setAttr ($toPoint+".inheritsTransform") 0;
  254.  
  255.     select $toObj $toPoint;
  256.     $constrainNode = `pointConstraint -weight 1`;
  257.     setAttr ($constrainNode[0]+".visibility") 0;
  258.     select $toObj $toPoint;
  259.     $constrainNode = `orientConstraint -weight 1`;
  260.     setAttr ($constrainNode[0]+".visibility") 0;
  261.     markObjectWithAttribute($toPoint, $group, "lightningToPosition");
  262.  
  263.     select -cl;
  264.     string $toJoint1 = `joint -p 0 0 0`;
  265.     string $toJoint2 = `joint -p 3 0 0`;
  266.     joint -e -zso -oj xyz $toJoint2;
  267.     setAttr ($toJoint2+".visibility") 0;
  268.     setAttr ($toJoint1+".template") 1;
  269.  
  270.     select $toPoint $toJoint1;
  271.     $constrainNode = `pointConstraint -weight 1`;
  272.     setAttr ($constrainNode[0]+".visibility") 0;
  273.  
  274.     // Create a locator as "toDirectionHandle".
  275.     //
  276.     vector $toHandleP = $toV - $diffV * 0.2;
  277.  
  278.     createPrimitive nullObject;
  279.     move ($toHandleP.x) ($toHandleP.y) ($toHandleP.z);
  280.     rename "toDirHandle#";
  281.     $sl = `ls -sl`;
  282.     string $toDirHandle = $sl[0];
  283.     parent $toDirHandle $toPoint;
  284.  
  285.     select $toDirHandle $toJoint2;
  286.     $constrainNode = `pointConstraint -weight 1`;
  287.     setAttr ($constrainNode[0]+".visibility") 0;
  288.  
  289.     // Create a locator as "toDirection".
  290.     // "toDirection" point-constrained to "toDirectionHandle".
  291.     //
  292.     createPrimitive nullObject;
  293.     move ($toHandleP.x) ($toHandleP.y) ($toHandleP.z);
  294.     rename "toDir#";
  295.     $sl = `ls -sl`;
  296.     string $toDirection = $sl[0];
  297.     setAttr ($toDirection+".visibility") 0;
  298.     setAttr ($toDirection+".inheritsTransform") 0;
  299.     parent $toDirection $toPoint;
  300.  
  301.     select $toDirHandle $toDirection;
  302.     $constrainNode = `pointConstraint -weight 1`;
  303.     setAttr ($constrainNode[0]+".visibility") 0;
  304.     markObjectWithAttribute($toDirection, $group, "lightningToDirection");
  305.  
  306.     // Group the "to" controls.
  307.     //
  308.     select $toJoint1 $toPoint;
  309.     group;
  310.     rename("toControl#");
  311.     string $toControl = getSelectedObject( 0 );
  312.  
  313.  
  314.     // Create lightning curve.
  315.     //
  316.     string $curveCmd = "curve -name \"lightningCurve#\" -d 1";
  317.     if( $segmentCount < 5 )
  318.         $segmentCount = 5;
  319.     int $i;
  320.     for( $i = 0; $i <= $segmentCount; $i ++ )
  321.     {
  322.         float $ratio = $i / $segmentCount;
  323.         vector $newPos = $fromV + $diffV * $ratio;
  324.         $curveCmd += (" -p "+($newPos.x)+" "+($newPos.y)+" "+($newPos.z));
  325.         $curveCmd += (" -k " + $i);
  326.     }
  327.  
  328.     string $curve = eval( $curveCmd );
  329.     setAttr ($curve+".visibility") 0;
  330.  
  331.     // Extrude lightning surface.
  332.     //
  333.     circle -c 0 0 0 -nr 0 0 1 -sw 360 -r .1 -d 3 -ut 0 -tol 0.01 -s 4 -ch 0;
  334.     string $circles[] = `ls -sl`;
  335.     string $circle = $circles[0];
  336.     setAttr ($circle+".visibility") 0;
  337.  
  338.     // Let "thickness" modifys the circle.scale.
  339.     //
  340.     connectAttr ($group+".thickness") ($circle+".scaleX");
  341.     connectAttr ($group+".thickness") ($circle+".scaleY");
  342.     connectAttr ($group+".thickness") ($circle+".scaleZ");
  343.  
  344.     extrude -ch true -rn false -po 0 -et 1 -ucp 1 -fpt 1 -upn 1 -rotation 0 -scale 1 $circle $curve;
  345.     rename "LightningSurface#";
  346.  
  347.     string $surfaces[] = `ls -sl`;
  348.     string $surface = $surfaces[0];
  349.     //setAttr ($surface+".template") 1;
  350.     markObjectWithAttribute( $surface, $group, "lightningSurface" );
  351.  
  352.     // Do not allow to do transformation on the lightning group.
  353.     //
  354.     lockTransformations( $surface );
  355.  
  356.     // Create soft curve for lightning.
  357.     //
  358.     select $curve;
  359.     string $particleTransform[] = `soft`;
  360.     select $particleTransform[0];
  361.     pickWalk -d down;
  362.     string $selected[] = `ls -sl`;
  363.     string $particleShape = $selected[0];
  364.     setAttr ($particleTransform[0]+".visibility") 0;
  365.     markObjectWithAttribute($particleShape, $group, "lightningParticleObject");
  366.  
  367.     // Group lightning geometries.
  368.     //
  369.     select $curve $circle;
  370.     group;
  371.     rename("controlGeometries#");
  372.     string $geometry = getSelectedObject( 0 );
  373.  
  374.  
  375.     // parenting operations.
  376.     //
  377.     parent $fromControl $group;
  378.     parent $toControl $group;
  379.     parent $geometry $group;
  380.     parent $surface $group;
  381.  
  382.     // Display the select-handle at the the center of the lightning surface.
  383.     //
  384.     vector $handlePos = $fromV + ($diffV * 0.5);
  385.     float $x = $handlePos.x;
  386.     float $y = $handlePos.y;
  387.     float $z = $handlePos.z;
  388.     setAttr ($group+".selectHandle") -type double3 $x $y $z;
  389.     setAttr ($group+".displayHandle") 1;
  390.  
  391.     // create expression to display group selection handle at the center
  392.     // of the lightning curve.
  393.     //
  394.     createLightningSelectHandleExpr( $group );
  395.  
  396.     return $group;
  397. }
  398.  
  399. proc createLightningExpression( string $group )
  400. {
  401.     // Get the object from which the lightning is coming.
  402.     //
  403.     string $fromObjs[] = getLightningFromPoint( $group );
  404.     string $fromObj = $fromObjs[0];
  405.  
  406.     string $fromDirs[] = getLightningFromDirection( $group );
  407.     string $fromDirection = $fromDirs[0];
  408.  
  409.     // Get the object from which the lightning is ending.
  410.     //
  411.     string $toObjs[] = getLightningToPoint( $group );
  412.     string $toObj = $toObjs[0];
  413.  
  414.     string $toDirs[] = getLightningToDirection( $group );
  415.     string $toDirection = $toDirs[0];
  416.  
  417.     // Get the particle object.
  418.     //
  419.     string $particles[] = getLightningParticle( $group );
  420.     string $particleShape = $particles[0];
  421.  
  422.     // Add expression to soft curve particle object.
  423.     //
  424.     string $expression = "";
  425.     $expression += ("vector $from = << "+$fromObj+".translateX, "+$fromObj+".translateY, "+$fromObj+".translateZ >>;\n");
  426.     $expression += ("vector $to = << "+$toObj+".translateX, "+$toObj+".translateY, "+$toObj+".translateZ >>;\n");
  427.  
  428.     $expression += ("vector $diffV = $to - $from;\n");
  429.     //$expression += ("float $dist = mag($diffV);\n");
  430.     $expression += ("float $ratio = id / ( count - 1 );\n");
  431.     $expression += ("$ratio = "+$group+".lightningStart + ($ratio * ("+$group+".lightningEnd - "+$group+".lightningStart));\n");
  432.  
  433.     $expression += ("//\n");
  434.     $expression += ("// vector $newP = $from + $diffV * $ratio;\n");
  435.     $expression += ("//\n");
  436.  
  437.     $expression += ("vector $fromDirP = << "+$fromDirection+".tx, "+$fromDirection+".ty, "+$fromDirection+".tz >>;\n");
  438.     $expression += ("vector $toDirP = << "+$toDirection+".tx, "+$toDirection+".ty, "+$toDirection+".tz >>;\n");
  439.  
  440.     $expression += ("vector $fromDir = ( $fromDirP - $from ) * 5.0;\n");
  441.     $expression += ("vector $toDir = ( $to - $toDirP ) * 5.0;\n");
  442.     $expression += ("$newP = hermite($from,$to,$fromDir,$toDir,$ratio);\n");
  443.  
  444.     $expression += ("// if( ( id != 0 ) && ( id != ( count - 1 ) ) )\n");
  445.     $expression += ("{\n");
  446.     $expression += ("\tfloat $spread = 0;\n");
  447.     $expression += ("\tif( $ratio < .5 )\n");
  448.     $expression += ("\t\t$spread = linstep( 0, .5, $ratio ) * " + $group + ".maxSpread;\n");
  449.     $expression += ("\telse\n");
  450.     $expression += ("\t\t$spread = ( 1.0 - linstep( .5, 1, $ratio ) ) * " + $group + ".maxSpread;\n");
  451.     $expression += ("\t$spread = $spread * ( " + $group + ".lightningEnd - " + $group + ".lightningStart );\n");
  452.     $expression += ("\t$newP += sphrand( $spread );\n");
  453.     $expression += ("}\n");
  454.     $expression += ("position = $newP;\n");
  455.  
  456.     dynExpression -c -s $expression $particleShape;
  457.     dynExpression -r -s $expression $particleShape;
  458. }
  459.  
  460. proc addLightningPointLight( string $group )
  461. {
  462.     // Create a default point light.
  463.     //
  464.     defaultPointLight(1, 1,1,1, 0, 0, 0,0,0, 1);
  465.     string $pointLight = getSelectedObject( 0 );
  466.     string $lightShape = getShapeFromObject( $pointLight, 0, 0 );
  467.  
  468.     // connect the pointLight.translate with $group.selectHandle.
  469.     //
  470.     parent $pointLight $group;
  471.  
  472.     connectAttr -f ($group+".selectHandle") ($pointLight+".translate");
  473.  
  474.     connectAttr -f ($group+".colorR") ($lightShape+".colorR");
  475.     connectAttr -f ($group+".colorG") ($lightShape+".colorG");
  476.     connectAttr -f ($group+".colorB") ($lightShape+".colorB");
  477.  
  478.     // Create expression to control the light intensity with
  479.     // lightning.glowIntensity.
  480.     //
  481.     string $lightIntensity = ($pointLight+".intensity");
  482.  
  483.     string $expr = "";
  484.     $expr += ("float $start = "+$group+".lightningStart;\n");
  485.     $expr += ("float $end = "+$group+".lightningEnd;\n");
  486.     $expr += ("float $glowIntensity = "+$group+".glowIntensity;\n");
  487.     $expr += ("float $lightIntensity = "+$group+".lightIntensity;\n");
  488.     $expr += ("float $intensity = $lightIntensity * $glowIntensity;\n");
  489.     $expr += ("$glowIntensity = $intensity * (abs($end-$start));\n");
  490.     $expr += ($lightIntensity+" = $glowIntensity;\n");
  491.  
  492.     expression -alwaysEvaluate false -string $expr;
  493. }
  494.  
  495. proc string makeLightning
  496.     (
  497.         string $name,
  498.         string $fromObj,
  499.         string $toObj,
  500.         int $segmentCount,
  501.         float $thickness,
  502.         float $maxSpread,
  503.         float $start,
  504.         float $end,
  505.         float $glowIntensity
  506.     )
  507. {
  508.     string $group = makeLightningGroup( $name, $fromObj, $toObj,
  509.                                         $segmentCount, $thickness, $maxSpread,
  510.                                         $start, $end, $glowIntensity );
  511.  
  512.     // Create the expression in particle object.
  513.     //
  514.     createLightningExpression( $group );
  515.  
  516.     // Add a point light at the location of the lightning center.
  517.     //
  518.     addLightningPointLight( $group );
  519.  
  520.     return( $group );
  521. }
  522.  
  523. global proc string createShader( string $group )
  524. {
  525.     string $shader = `shadingNode -asShader lambert -name LigntningShader`;
  526.     markObjectWithAttribute( $shader, $group, "lightningShader" );
  527.  
  528.     string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($shader+"SG")`;
  529.  
  530.     setAttr ($shader+".color") -type double3 0 0 0;
  531.     setAttr ($shader+".incandescence") -type double3 .5 1 1;
  532.     setAttr ($shader+".hideSource") 0;
  533.  
  534.     connectAttr -f ($group+".glowIntensity") ($shader+".glowIntensity");
  535.  
  536.     connectAttr -f ($group+".colorR") ($shader+".incandescenceR");
  537.     connectAttr -f ($group+".colorG") ($shader+".incandescenceG");
  538.     connectAttr -f ($group+".colorB") ($shader+".incandescenceB");
  539.  
  540.     connectAttr -f ($group+".colorR") ($shader+".colorR");
  541.     connectAttr -f ($group+".colorG") ($shader+".colorG");
  542.     connectAttr -f ($group+".colorB") ($shader+".colorB");
  543.  
  544.     connectAttr -f ($shader+".outColor") ($shadingGroup+".surfaceShader");
  545.  
  546.     return $shadingGroup;
  547. }
  548.  
  549. global proc int isLightningGroup( string $object )
  550. {
  551.     if( `objExists $object` == 0 )
  552.         return 0;
  553.  
  554.     if( `attributeQuery -node $object -exists "_lightningGroupObject"` == 1 )
  555.         return 1;
  556.     else
  557.         return 0;
  558. }
  559.  
  560. global proc string[] getLightningFromObject( string $group )
  561. {
  562.     string $result[];
  563.     clear( $result );
  564.  
  565.     if( isLightningGroup( $group ) == 0 )
  566.     {
  567.         error("The object, \""+$group+"\", is not a lightning group object.");
  568.         return( $result );
  569.     }
  570.  
  571.     $result = getMarkedObjects( $group, "lightningFromObject" );
  572.     return( $result );
  573. }
  574.  
  575. global proc string[] getLightningFromPoint( string $group )
  576. {
  577.     string $result[];
  578.     clear( $result );
  579.  
  580.     if( isLightningGroup( $group ) == 0 )
  581.     {
  582.         error("The object, \""+$group+"\", is not a lightning group object.");
  583.         return( $result );
  584.     }
  585.  
  586.     $result = getMarkedObjects( $group, "lightningFromPosition" );
  587.     return( $result );
  588. }
  589.  
  590. global proc string[] getLightningFromDirection( string $group )
  591. {
  592.     string $result[];
  593.     clear( $result );
  594.  
  595.     if( isLightningGroup( $group ) == 0 )
  596.     {
  597.         error("The object, \""+$group+"\", is not a lightning group object.");
  598.         return( $result );
  599.     }
  600.  
  601.     $result = getMarkedObjects( $group, "lightningFromDirection" );
  602.     return( $result );
  603. }
  604.  
  605. global proc string[] getLightningToObject( string $group )
  606. {
  607.     string $result[];
  608.     clear( $result );
  609.  
  610.     if( isLightningGroup( $group ) == 0 )
  611.     {
  612.         error("The object, \""+$group+"\", is not a lightning group object.");
  613.         return( $result );
  614.     }
  615.  
  616.     $result = getMarkedObjects( $group, "lightningToObject" );
  617.     return( $result );
  618. }
  619.  
  620. global proc string[] getLightningToPoint( string $group )
  621. {
  622.     string $result[];
  623.     clear( $result );
  624.  
  625.     if( isLightningGroup( $group ) == 0 )
  626.     {
  627.         error("The object, \""+$group+"\", is not a lightning group object.");
  628.         return( $result );
  629.     }
  630.  
  631.     $result = getMarkedObjects( $group, "lightningToPosition" );
  632.     return( $result );
  633. }
  634.  
  635. global proc string[] getLightningToDirection( string $group )
  636. {
  637.     string $result[];
  638.     clear( $result );
  639.  
  640.     if( isLightningGroup( $group ) == 0 )
  641.     {
  642.         error("The object, \""+$group+"\", is not a lightning group object.");
  643.         return( $result );
  644.     }
  645.  
  646.     $result = getMarkedObjects( $group, "lightningToDirection" );
  647.     return( $result );
  648. }
  649.  
  650. global proc string[] getLightningParticle( string $group )
  651. {
  652.     string $result[];
  653.     clear( $result );
  654.  
  655.     if( isLightningGroup( $group ) == 0 )
  656.     {
  657.         error("The object, \""+$group+"\", is not a lightning group object.");
  658.         return( $result );
  659.     }
  660.  
  661.     $result = getMarkedObjects( $group, "lightningParticleObject" );
  662.     return( $result );
  663. }
  664.  
  665. global proc string[] getLightningSurface( string $group )
  666. {
  667.     string $result[];
  668.     clear( $result );
  669.  
  670.     if( isLightningGroup( $group ) == 0 )
  671.     {
  672.         error("The object, \""+$group+"\", is not a lightning group object.");
  673.         return( $result );
  674.     }
  675.  
  676.     $result = getMarkedObjects( $group, "lightningSurface" );
  677.     return( $result );
  678. }
  679.  
  680. global proc string[] getLightningShader( string $group )
  681. {
  682.     string $result[];
  683.     clear( $result );
  684.  
  685.     if( isLightningGroup( $group ) == 0 )
  686.     {
  687.         error("The object, \""+$group+"\", is not a lightning group object.");
  688.         return( $result );
  689.     }
  690.  
  691.     $result = getMarkedObjects( $group, "lightningShader" );
  692.     return( $result );
  693. }
  694.  
  695. global proc addControlAttribute
  696.     ( string $node, string $attr, float $value, float $min, float $max )
  697. {
  698.     // Add attributes for lightning controls.
  699.     //
  700.     addAttr -ln $attr -at "float" -dv $value -min $min -max $max $node;
  701.     setAttr -keyable true ($node+"."+$attr);
  702. }
  703.  
  704. global proc string[] lightning
  705.     (
  706.         string $name,
  707.         int $grouping,
  708.         int $createOption,
  709.         int $segmentCount,
  710.         float $thickness,
  711.         float $maxSpread,
  712.         float $start,
  713.         float $end,
  714.         float $glowIntensity
  715.     )
  716. //
  717. // Description:
  718. //
  719. //    This is the main lightning procedure.  It decides how to create
  720. // the lightning bolts based on the given arguments.
  721. //
  722. {
  723.     string $bolts[];
  724.     clear($bolts);
  725.     if( `licenseCheck -type complete` == 0 )
  726.     {
  727.         error("You are not licensed to use the Lightning Effect.");
  728.         return $bolts;
  729.     }
  730.  
  731.     string $selectedList[] = getSelectedList( "transforms" );
  732.  
  733.     if( size($selectedList) < 2 )
  734.     {
  735.         error("Must have at least two transforms selected for this effect.");
  736.         return $bolts;
  737.     }
  738.  
  739.     int $from, $to;
  740.     string $fromObj, $toObj, $group, $surface;
  741.     string $surfaces[];
  742.     int $count = size( $selectedList );
  743.  
  744.     // Option 1: create lightning in between all pairs.
  745.     //
  746.     if( $createOption == 1 )
  747.     {
  748.         for( $from = 0; $from < ($count - 1); $from ++ )
  749.         {
  750.             $fromObj = $selectedList[$from];
  751.             for( $to = ( $from + 1 ); $to < $count; $to ++ )
  752.             {
  753.                 $toObj = $selectedList[$to];
  754.  
  755.                 // Create a lightning effect from $fromObj to $toObj.
  756.                 //
  757.                 $group = makeLightning( $name, $fromObj, $toObj,
  758.                                     $segmentCount, $thickness, $maxSpread,    
  759.                                     $start, $end, $glowIntensity );
  760.  
  761.                 // Add shader for the new lightning surface.
  762.                 //
  763.                 string $shader = createShader( $group );
  764.                 $surfaces = getLightningSurface( $group );
  765.                 sets -e -forceElement $shader $surfaces;
  766.  
  767.                 $bolts[size($bolts)] = $group;
  768.             }
  769.         }
  770.     }
  771.     // Option 2: create lightning in between two objects "In Order"
  772.     // of the selected list.
  773.     else if( $createOption == 2 )
  774.     {
  775.         for( $from = 0; $from < ($count - 1); $from ++ )
  776.         {
  777.             $fromObj = $selectedList[$from];
  778.             $toObj = $selectedList[$from + 1];
  779.  
  780.             // Create a lightning effect from $fromObj to $toObj.
  781.             //
  782.             $group = makeLightning( $name, $fromObj, $toObj,
  783.                                     $segmentCount, $thickness, $maxSpread,    
  784.                                     $start, $end, $glowIntensity );
  785.  
  786.             // Add shader for the new lightning surface.
  787.             //
  788.             string $shader = createShader( $group );
  789.             $surfaces = getLightningSurface( $group );
  790.             sets -e -forceElement $shader $surfaces;
  791.  
  792.             $bolts[size($bolts)] = $group;
  793.         }
  794.     }
  795.     // Option 3: create lightning in between the first selected object
  796.     // and all others from the second in the selected list.
  797.     else if( $createOption == 3 )
  798.     {
  799.         $fromObj = $selectedList[0];
  800.         for( $to = 1; $to < $count; $to ++ )
  801.         {
  802.             $toObj = $selectedList[$to];
  803.  
  804.             // Create a lightning effect from $fromObj to $toObj.
  805.             //
  806.             $group = makeLightning( $name, $fromObj, $toObj,
  807.                                     $segmentCount, $thickness, $maxSpread,    
  808.                                     $start, $end, $glowIntensity );
  809.  
  810.             // Add shader for the new lightning surface.
  811.             //
  812.             string $shader = createShader( $group );
  813.             $surfaces = getLightningSurface( $group );
  814.             sets -e -forceElement $shader $surfaces;
  815.  
  816.             $bolts[size($bolts)] = $group;
  817.         }
  818.     }
  819.  
  820.     if( $grouping && (size($bolts) > 1) )
  821.     {
  822.         select $bolts;
  823.         group;
  824.         rename("LightningGroup#");
  825.         string $lightningGroup = getSelectedObject( 0 );
  826.         select $lightningGroup;
  827.     }
  828.     else
  829.     {
  830.         select $bolts;
  831.     }
  832.  
  833.     return $bolts;
  834. }
  835.